type-c-service: Migrate to async function calls#833
Conversation
0e41390 to
39cc831
Compare
Cargo Vet Audit Passed
|
de3f1b1 to
352e330
Compare
Transitioning away from the last bit of messaging code, no longer needed.
6e6e4b4 to
a4c73a2
Compare
a4c73a2 to
dd967cd
Compare
There was a problem hiding this comment.
Pull request overview
Refactors the Type-C service from a centralized Context + Bridge-based messaging architecture to direct async method calls on locked port objects. The Type-C service now operates over a generic Registration trait that exposes ports as &[&Port] and uses per-port event channels plus a new event receiver abstraction.
Changes:
- Delete the
bridgemodule and theservice::context::Contextrequest/response indirection; the service now callsPd/UcsiLpmtrait methods directly on locked ports. - Introduce
service::registration::{Registration, ArrayRegistration}andservice::event_receiver::ArrayEventReceiver; require port traits (Pd,Retimer,Controller,Lpm,SystemPowerStateStatus) to beNamed. - Carry a port reference (
&'port Port) inPortEvent/Eventinstead ofGlobalPortId, and splitEventfromEventData.
Reviewed changes
Copilot reviewed 41 out of 44 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| type-c-service/src/service/mod.rs | Replaces Context/cached port_status state with generic Registration; rewrites event types around port references |
| type-c-service/src/service/ucsi.rs | UCSI processing now operates on locked port refs; reorganized state fields |
| type-c-service/src/service/power.rs | Iterates over registration.ports() instead of using context; updates power policy event variant pattern |
| type-c-service/src/service/registration.rs | New Registration trait + ArrayRegistration implementation |
| type-c-service/src/service/event_receiver.rs | New ArrayEventReceiver / ArrayPortReceivers replacing old EventReceiver |
| type-c-service/src/service/vdm.rs | File removed (VDM helpers no longer routed through service) |
| type-c-service/src/task.rs | task is now generic over registration and the new event receiver |
| type-c-service/src/controller/*.rs | Port struct gains a TypeCSender, removes global_port/context; all trait impls updated |
| type-c-service/src/controller/macros.rs | Macro adds a Type-C event channel; create signature drops global port id and context |
| type-c-service/src/bridge/*.rs | Bridge module deleted |
| type-c-service/src/lib.rs | Remove pub mod bridge |
| type-c-interface/src/service/context.rs | Context module removed |
| type-c-interface/src/service/event.rs | PortEvent/Event now carry &'port Port; split into Event + EventData |
| type-c-interface/src/service/mod.rs | Drops pub mod context |
| type-c-interface/src/port/{pd,retimer,power}.rs | Traits require Named supertrait |
| type-c-interface/src/port/mod.rs | Drops Command/Response/Device types (no longer needed without bridge) |
| type-c-interface/src/port/event.rs | Adjust imports after port::mod slimming |
| type-c-interface/src/controller/{mod,pd,power,retimer}.rs | Traits require Named supertrait |
| type-c-interface/src/ucsi.rs | Lpm trait requires Named |
| type-c-interface/Cargo.toml | Drops embassy-sync/embassy-time deps no longer needed |
| examples/std/src/lib/type_c/mock_controller.rs | Adds name field and Named impl; Port type gains TypeCSender param |
| examples/std/src/bin/type_c/{service,ucsi,unconstrained}.rs | Update to new registration/event-receiver wiring; remove bridge tasks |
| examples/std/src/bin/type_c/basic.rs | Example removed |
| examples/std/Cargo.toml | Drops the type-c-basic binary |
| examples/rt685s-evk/src/bin/{type_c,type_c_cfu}.rs | Update example wiring; remove bridge task; second port now uses LocalPortId(1) |
| Cargo.lock / examples/*/Cargo.lock | Lockfile updates |
Continue moving away from context type. Application code must now setup communication channels between port code and the type-C service.
Any device should have a human readable name.
Remove most uses of this type, limited it mostly to the UCSI code. Service events now deal directly with referencs to port objects. Remove port state stored in service implementation.
dd967cd to
42ce430
Compare
|
|
||
| /// Process a UCSI command | ||
| pub async fn process_ucsi_command(&mut self, command: &GlobalCommand) -> UcsiResponse { | ||
| pub async fn process_ucsi_command(&mut self, port: &'port Reg::Port, command: &GlobalCommand) -> UcsiResponse { |
There was a problem hiding this comment.
Does the client call this? Is the assumption that command will always be for the port passing in? Like the GlobalPortId within GlobalCommand will match the port referece passed in?
| for port in self.registration.ports().iter() { | ||
| port.lock() | ||
| .await | ||
| .set_unconstrained_power(ptr::eq(*port, unconstrained_port)) |
There was a problem hiding this comment.
The logic seems to have inverted from the previous behavior:
- If it is the unconstrained port, then it is true, so it is unconstrained.
- If it is not the unconstrained port, then it is false, so it is constrained
Contexttype, application code is now responsible for creating event senders/receiversGlobalPortIdusage